home *** CD-ROM | disk | FTP | other *** search
- /*
- CommandPeriod.c
-
- Checks the event queue and returns 1 if user typed Command-period.
- This uses the System call IsCmdChar() to recognize Command-period,
- which is supposed to work even on international keyboards.
-
- If there are other unprocessed key presses ahead of the command-period key press
- then we won't detect the command-period until they've been removed from the queue.
- We only examine the key press that's at the top of the queue.
-
- HISTORY:
- 3/97 dgp wrote it.
- 3/19/97 dgp David Brainard noticed that we were treating plain period as equivalent to command-period.
- It turns out that I hadn't read the documentation for IsCmdChar() carefully enough. It
- doesn't check for the Command key, so I've added an explicit test for the command key.
- Now allow for an "autoKey" as well as a "keyDown" event.
- 4/10/97 dgp Eliminate stuff that was conditional on !UNIVERSAL_HEADERS.
-
- NOTES:
- http://devworld.apple.com/dev/techsupport/develop/issue22/macqa.html
- http://devworld.apple.com/dev/technotes/te/te_23.html
-
- The following is copied from Apple's develop 22 Q&A (June 1996). As of January 1997 this is still
- the only documentation that Apple has provided for this function, despite claims to
- have added it to the Macintosh Technical Note "International Canceling" (TE 23).
-
- extern pascal Boolean IsCmdChar(const EventRecord *event, short test);
-
- This function tests whether the Command key is being pressed in conjunction with another key (or
- keys) that could generate testChar for some combination of Command up or down and Shift up or
- down. This accommodates European keyboards that may have testChar as a shifted character, and
- non-Roman keyboards that will only generate testChar if Command is down. It's most useful for
- testing for Command-period.
-
- The caller passes in the event record, which is assumed by the function to be an event record for a
- key-down or auto-key event with the Command key down. The caller also passes in the character to
- be tested for (for example, '.'). The function returns TRUE if testChar is produced with the current
- modifier keys, or if it would be produced by changing the current modifier key bits in either or both
- of the following ways:
-
- turning the Command bit off
-
- toggling the Shift bit
-
- "That routine was introduced with System 7." [To test for availability, just check for System 7.]
- */
- #include "VideoToolbox.h"
- // IsCmdChar() documented in develop 22 Q&A.
- #ifndef __SCRIPT__
- #include <Script.h> // IsCmdChar
- #endif
-
- Boolean CommandPeriod(void)
- {
- static Boolean firstTime=1;
- long version;
- EventRecord event;
-
- if(firstTime){
- // Make sure IsCmdChar() trap is available.
- Gestalt(gestaltSystemVersion,&version);
- if(version<0x700)PrintfExit("%s: require System 7.\n",__FILE__);
- firstTime=0;
- }
- if(EventAvail(keyDownMask|autoKeyMask,&event) && IsCmdChar(&event,'.') && (event.modifiers & cmdKey)){
- GetNextEvent(keyDownMask|autoKeyMask,&event); // consume the event.
- return 1;
- }else return 0;
- }
-
- short GetNextEventOrQuit(int mask,EventRecord *eventPtr)
- {
- if(CommandPeriod()){
- #if MATLAB
- PrintfExit("User typed cmd-. EXITING.");
- #else
- PrintfExit("\nUser typed cmd-. EXITING.\n");
- #endif
- }
- return GetNextEvent(mask,eventPtr);
- }
-
- Boolean WaitNextEventOrQuit(int mask,EventRecord *eventPtr,unsigned long sleep,RgnHandle mouseRgn)
- {
- if(CommandPeriod()){
- #if MATLAB
- PrintfExit("User typed cmd-. EXITING.");
- #else
- PrintfExit("\nUser typed cmd-. EXITING.\n");
- #endif
- }
- return WaitNextEvent(mask,eventPtr,sleep,mouseRgn);
- }
-